package com.cmcc.xdr.message;

import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.cmcc.xdr.entity.ComposedEntity;

public class SynComposedMsg extends SingleSigMsg {

	public ComposedEntity composed = new ComposedEntity();

	private static SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	//重新构造一条单独存公共信息和通用信息的记录，单接口补0，无实际意义，只做填充使用
	public SynComposedMsg(SingleSigGlobalMsg globalMsg) {
		//公共信息
		composed.setLength(globalMsg.getTotalLength());
		composed.setLocalProvince(globalMsg.getLocalProvince());
		composed.setLocalCity(globalMsg.getLocalCity());
		composed.setOwnerProvince(globalMsg.getOwnerProvince());
		composed.setOwnerCity(globalMsg.getOwnerCity());
		composed.setRoamingType(globalMsg.getRoamingType());
		composed.setInterface(globalMsg.getInterfaceType());
 		composed.setXdrType(globalMsg.getXdrType());
 		composed.setXdrId(globalMsg.getXdrID());
		composed.setRat(globalMsg.getRat());
		composed.setImsi(globalMsg.getImsi());
		composed.setImeisv(globalMsg.getImeisv());
		composed.setMsisdn(globalMsg.getMsisdn());
		//通用信息
		composed.setProcedureType(globalMsg.getProcedureType());
		composed.setProcedureStartTime(new Date(globalMsg.getProcedureStartTime()));//composed.setProcedureStartTime(new Date(loadLong(8)));
		composed.setProcedureEndTime(new Date(globalMsg.getProcedureEndTime()));//composed.setProcedureEndTime(new Date(loadLong(8)));
		composed.setProcedureStatus(globalMsg.getProcedureStatus());
		composed.setCallingNumber(globalMsg.getCallingNumber());
		composed.setCalledNumber(globalMsg.getCalledNumber());
		composed.setServiceType(0); // 240规范开发，419 版没有数据，暂时预留
		composed.setResponseCode(0); // 240规范开发，419 版没有数据，暂时预留
		composed.setReasonCause(0); //  240规范开发，419 版没有数据，暂时预留
		composed.setFirstFailTime(0); //  240规范开发，419 版没有数据，暂时预留
		composed.setFirstFailNeIp(""); //  240规范开发，419 版没有数据，暂时预留
		composed.setXdrnumber(globalMsg.getXdrNumber());
		composed.setFinishReasonCause(0);//  240规范开发，419 版没有数据，暂时预留
		//单接口行和公共信息行标识
		composed.setSingleXdrId("0");//   
		//单接口信息
		composed.setInterface(0);
		composed.setSingleProcedureType(0);		
		composed.setSingleStartTime(new Date());
		composed.setSingleEndTime(new Date());
		composed.setCallSide(0);
		composed.setSingleProcedureStat(0);
		composed.setSourceNeIP("0");
		composed.setSourceNePort(0);
		composed.setDestinationNeIP("0");
		composed.setDestinationNePort(0);
		composed.setAlertingTime(0);// 240规范开发，419 版没有数据，暂时预留
		composed.setAnswerTime(0);// 240规范开发，419 版没有数据，暂时预留
		composed.setSvResult(0);// 240规范开发，419 版没有数据，暂时预留
		composed.setSvRespDelay(0);// 240规范开发，419 版没有数据，暂时预留
		composed.setSvDelay(0);// 240规范开发，419 版没有数据，暂时预留
		composed.setInsertDate(format.format(new Date()));
	}
	public SynComposedMsg(ByteBuffer buffer,SingleSigGlobalMsg globalMsg) {
		this.setBuffer(buffer);
		this.setSSGMsg(globalMsg);
		//公共信息
		composed.setLength(globalMsg.getTotalLength());
		composed.setLocalProvince(globalMsg.getLocalProvince());
		composed.setLocalCity(globalMsg.getLocalCity());
		composed.setOwnerProvince(globalMsg.getOwnerProvince());
		composed.setOwnerCity(globalMsg.getOwnerCity());
		composed.setRoamingType(globalMsg.getRoamingType());
		//composed.setInterface(globalMsg.getInterfaceType());
 		composed.setXdrType(globalMsg.getXdrType());
 		composed.setXdrId(globalMsg.getXdrID());
		composed.setRat(globalMsg.getRat());
		composed.setImsi(globalMsg.getImsi());
		composed.setImeisv(globalMsg.getImeisv());
		composed.setMsisdn(globalMsg.getMsisdn());
		//通用信息
		composed.setProcedureType(globalMsg.getProcedureType());
		composed.setProcedureStartTime(new Date(globalMsg.getProcedureStartTime()));//composed.setProcedureStartTime(new Date(loadLong(8)));
		composed.setProcedureEndTime(new Date(globalMsg.getProcedureEndTime()));//composed.setProcedureEndTime(new Date(loadLong(8)));
		composed.setProcedureStatus(globalMsg.getProcedureStatus());
		composed.setCallingNumber(globalMsg.getCallingNumber());
		composed.setCalledNumber(globalMsg.getCalledNumber());
		composed.setServiceType(0); // 240规范开发，419 版没有数据，暂时预留
		composed.setResponseCode(0); // 240规范开发，419 版没有数据，暂时预留
		composed.setReasonCause(0); //  240规范开发，419 版没有数据，暂时预留
		composed.setFirstFailTime(0); //  240规范开发，419 版没有数据，暂时预留
		composed.setFirstFailNeIp(""); //  240规范开发，419 版没有数据，暂时预留
		composed.setXdrnumber(globalMsg.getXdrNumber());
		composed.setFinishReasonCause(0);//  240规范开发，419 版没有数据，暂时预留
    		
		//单接口信息
		composed.setInterface(loadInt(1));
		composed.setSingleXdrId(loadHexStr(16));
		composed.setSingleProcedureType(loadInt(1));		
		composed.setSingleStartTime(new Date(loadLong(8)));
		composed.setSingleEndTime(new Date(loadLong(8)));
		if(composed.getInterface().intValue()==18&&composed.getProcedureType().intValue() == 5 ){
			if( composed.getProcedureStatus().intValue() == 2 || composed.getProcedureStatus().intValue() == 4){
				int callSide = 0;//TODO:SdtpDao.getXdrComposedCallSide(composed.getSingleXdrId());
			    composed.setCallSide(callSide);
			}else{
				composed.setCallSide(0);
			}
		}else{
			composed.setCallSide(0);
		}
		composed.setSingleProcedureStat(loadInt(1));
		composed.setSourceNeIP(loadIp(16));
		composed.setSourceNePort(loadInt(2));
		composed.setDestinationNeIP(loadIp(16));
		composed.setDestinationNePort(loadInt(2));
		composed.setAlertingTime(0);// 240规范开发，419 版没有数据，暂时预留
		composed.setAnswerTime(0);// 240规范开发，419 版没有数据，暂时预留
		composed.setSvResult(0);// 240规范开发，419 版没有数据，暂时预留
		composed.setSvRespDelay(0);// 240规范开发，419 版没有数据，暂时预留
		composed.setSvDelay(0);// 240规范开发，419 版没有数据，暂时预留

		composed.setInsertDate(format.format(new Date()));
	}


	public ComposedEntity getComposed() {
		return composed;
	}

	public void setComposed(ComposedEntity composed) {
		this.composed = composed;
	}

}